package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IUserFriendService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.UserFriendCreateValidate;
import com.mdd.admin.validate.UserFriendUpdateValidate;
import com.mdd.admin.validate.UserFriendSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.UserFriendListedVo;
import com.mdd.admin.vo.UserFriendDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/friend")
@Api(tags = "用户好友列管理")
public class UserFriendController {

    @Resource
    IUserFriendService iUserFriendService;

    @GetMapping("/list")
    @ApiOperation(value="用户好友列列表")
    public AjaxResult<PageResult<UserFriendListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated UserFriendSearchValidate searchValidate) {
        PageResult<UserFriendListedVo> list = iUserFriendService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="用户好友列详情")
    public AjaxResult<UserFriendDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        UserFriendDetailVo detail = iUserFriendService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "用户好友列新增")
    @PostMapping("/add")
    @ApiOperation(value="用户好友列新增")
    public AjaxResult<Object> add(@Validated @RequestBody UserFriendCreateValidate createValidate) {
        iUserFriendService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "用户好友列编辑")
    @PostMapping("/edit")
    @ApiOperation(value="用户好友列编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody UserFriendUpdateValidate updateValidate) {
        iUserFriendService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "用户好友列删除")
    @PostMapping("/del")
    @ApiOperation(value="用户好友列删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iUserFriendService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
